﻿#!/usr/bin/env python
#coding:utf-8
#Code By Mango
#update:2014-7-24

from geColor import *
from gePlugin import *

class load:
    '''load mef plugin 载入插件'''
    def start(self,plutype,pluname):    # 'multi', 'multi/scan_port_thread'
        try:
            mm = m("plugins/%s.py"%pluname)    # plugins/multi/scan_port_thread.py
            while 1:
                mm.printp(plutype,pluname)
                pcmd=raw_input(">")
                if   pcmd == 'back' or pcmd == 'exit':
                    break    # 跳出这个循环,返回上一个循环
                elif pcmd == 'help':
                    mm.pluhelp()
                elif pcmd == 'cls':
                    mm.cls()
                elif pcmd == 'info':
                    mm.info()
                elif pcmd == 'opts':
                    mm.opt()
                elif pcmd == 'run':
                    mm.run()
                elif pcmd == 'load':
                    mm.load()
                elif pcmd == 'set':
                    color.cprint("[?] USAGE:set <PARAM> <VALUE>",YELLOW)
                elif len(pcmd.split(" ")) == 2:  # 如果命令有2个
                    ptmp = pcmd.split(" ")  # list ptmp = ['load','文件']
                    if ptmp[0] == "load":       # 直接执行某脚本
                        if len(ptmp[0])>0 and len(ptmp[1])>0:
                            execfile("plugins/load/%s.py" % ptmp[1])  # execfile()执行一个文件
                        else:
                            mm.load()
                elif len(pcmd.split(" "))==3:  # 如果命令有3个
                    ptmp=pcmd.split(" ")
                    if ptmp[0] == "set":
                        if len(ptmp[1])>0 and len(ptmp[2])>0:
                            mm.setp(ptmp[1],ptmp[2])   # 传递
                elif len(pcmd.split(" ")) == 4:
                    ptmp = pcmd.split(" ")
                    if ptmp[0] == "set":
                        if len(ptmp[1])>0 and len(ptmp[2]) and len(ptmp[3])>0:
                            mm.setp(ptmp[1],ptmp[2]+" "+ptmp[3])   # 传递
        except KeyboardInterrupt:
            color.cprint("\n[!] CTRL+C EXIT !",RED)
        except Exception,e:
            color.cprint("[!] ERR:%s"%e,RED)


if __name__ == '__main__':
    print __doc__
else:
    load=load()